package gui.arbre;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import yaut.Ressource;


import UML.Attribut;
import UML.Classe;
import UML.Lien;
import UML.Methode;

/**
 * Permet de modifier le rendu des feuilles de l'arbre
 * 
 * @author Delmas Gabriel
 */
class DefaultTreeCellRendererIconisable extends DefaultTreeCellRenderer
{
	private static final long serialVersionUID = 9048713079973488775L;

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
    {

		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		
		DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
		
		//Condition pour laquelle on veut changer l'icone
		if (node.getUserObject() instanceof Classe)
		{
		    //On affecte a la feuille une icone differente
		    setIcon(Ressource.image_ClasseJTree);
		}
		if (node.getUserObject() instanceof Attribut)
		{
			String visibilite=((Attribut) node.getUserObject()).getVisibilite();
			if(visibilite=="private")
			{
				setIcon(Ressource.image_AttributPrivateJTree);
			}
			else if(visibilite=="protected")
			{
				setIcon(Ressource.image_AttributProtectedJTree);
			}
			else
				setIcon(Ressource.image_AttributPublicJTree);
		    
		}
		if (node.getUserObject() instanceof Methode)
		{
	
			String visibilite=((Methode) node.getUserObject()).getVisibilite();
			if(visibilite=="private")
			{
				setIcon(Ressource.image_MethodePrivateJTree);
			}
			else if(visibilite=="protected")
			{
				setIcon(Ressource.image_MethodeProtectedJTree);
			}
			else
				setIcon(Ressource.image_MethodePublicJTree);
		}
		if (node.getUserObject() instanceof Lien)
		{
			//setIcon(Ressource.image_MethodePrivateJTree);
		}
		return this;
    }
 
}